<%--
  products.jsp
  作用：用户"我的商品"页面，展示用户发布的所有商品列表，并提供发布新商品的表单。
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的商品</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/layout.css">
</head>
<body>

<div class="main-container">
    <jsp:include page="/WEB-INF/parts/sidebar.jsp" />

    <main class="content-area">
        <jsp:include page="/WEB-INF/parts/header.jsp" />

        <div class="page-title">
            <h2>我的商品</h2>
        </div>

        <div class="profile-section">
            <h3>上传新商品</h3>
            <form action="${pageContext.request.contextPath}/user/addProduct" method="post" enctype="multipart/form-data">
                <div class="form-group">
                    <label for="name">商品名称</label>
                    <input type="text" id="name" name="name" class="form-control" required>
                </div>
                <div class="form-group">
                    <label for="price">金额 (元)</label>
                    <input type="number" id="price" name="price" class="form-control" step="0.01" required>
                </div>
                <div class="form-group">
                    <label for="description">基本信息 (如使用时间, 完好程度)</label>
                    <textarea id="description" name="description" class="form-control" rows="4" required></textarea>
                </div>
                <div class="form-group">
                    <label for="image">商品图片</label>
                    <input type="file" id="image" name="image" class="form-control-file" required>
                </div>
                <button type="submit" class="btn">上架商品</button>
            </form>
        </div>
        
        <div class="profile-section">
            <h3>我已上架的商品</h3>
            <div class="product-list-user">
                <c:if test="${empty products}">
                    <p class="empty-message" style="grid-column: 1 / -1;">您现在没有商品哦。</p>
                </c:if>
                <c:forEach var="product" items="${products}">
                    <div class="product-card-user">
                        <div class="product-image-user">
                            <img src="${pageContext.request.contextPath}/uploads/product_images/${product.imageUrl}" alt="${product.name}">
                        </div>
                        <div class="product-info-user">
                            <h4>${product.name}</h4>
                            <p class="price">¥ ${product.price}</p>
                            <p>状态: <span class="status-${product.status == 'on_shelf' ? 'active' : 'off_shelf'}">${product.status == 'on_shelf' ? '上架中' : '已下架'}</span></p>
                            <div class="product-actions-user">
                                <a href="${pageContext.request.contextPath}/user/editProduct?id=${product.id}" class="btn btn-secondary">编辑</a>
                                <c:choose>
                                    <c:when test="${product.status == 'on_shelf'}">
                                        <a href="${pageContext.request.contextPath}/user/productShelf?id=${product.id}&action=shelf_off" class="btn btn-warning" onclick="return confirm('确定要下架此商品吗？')">下架</a>
                                    </c:when>
                                    <c:otherwise>
                                        <a href="${pageContext.request.contextPath}/user/productShelf?id=${product.id}&action=shelf_on" class="btn btn-success" onclick="return confirm('确定要上架此商品吗？')">上架</a>
                                    </c:otherwise>
                                </c:choose>
                                <a href="${pageContext.request.contextPath}/user/deleteProduct?id=${product.id}" class="btn btn-danger" onclick="return confirm('确定要删除此商品吗？删除后不可恢复！')">删除</a>
                            </div>
                        </div>
                    </div>
                </c:forEach>
            </div>
        </div>

    </main>
</div>

</body>
</html> 